
/**
 * @description: 防抖
 * @param {*} callback
 * @param {*} time
 * @return {*}
 */
export function debounce(callback, time = 3000) {
  let timeId = null;
  return function (...args) {
    if (timeId !== null) {
      // 清空定时器
      clearTimeout(timeId);
    }
    timeId = setTimeout(() => {
      callback.call(this, ...args);
      timeId = null;
    }, time);
  };
}
/**
 * @description: 节流
 * @param {*} callback
 * @param {*} wait
 * @return {*}
 */
export function throttle(callback, wait = 300) {
  let start = 0;
  // console.log(callback);
  return function (...args) {
    let now = Date.now();
    if (now - start >= wait) {
      callback.call(this, ...args);
      start = now;
    }
  };
}
